package bamboo.drawingkid.views.components;

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.Ticker;

import bamboo.drawingkid.Main;


public class FormTemplate extends Form implements CommandListener{
	private ImageTable tempImage;
	private Ticker ticker;
	private Gauge gauge;
	public int tmpValue;
	public int currentValue;
	private Command cmdExit = new Command("Back", Command.BACK, 0);
	public FormTemplate(String title) {
		super(title);
		gauge = new Gauge("", true, 100, 50);
		ticker = new Ticker("Welcome to Drawing Kid");
		this.append(gauge);
		//gauge.setItemCommandListener(this);
		Timer timer = new Timer();
		currentValue = gauge.getValue();
		TimerTask timerTask = new TimerTask() {
			public void run() {
				tmpValue = gauge.getValue();
				// TODO Auto-generated method stub
				if(currentValue!=tmpValue){
					currentValue=tmpValue;
					System.out.println(gauge.getValue());
				}
			}
		};
		
		timer.scheduleAtFixedRate(timerTask,0,10);

		this.setTicker(ticker);
		for(int i =0;i<20;i++){
			//this.setTicker(ticker);
			tempImage = new ImageTable("/Icon_Brush.png");
		   	tempImage.setLayout(ImageItem.LAYOUT_DEFAULT);
		   	tempImage.setLabel("");
		   	this.append(tempImage);
		   	this.addCommand(cmdExit);
		   	this.setCommandListener(this);
		 }
	}
	
	public void commandAction(Command c, Displayable d) {
		// TODO Auto-generated method stub
		Main.getInstance().showDrawing();
	}
}
